package top.market.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import top.market.model.entity.Category;
import top.market.model.dto.QueryCategoryDTO;
import top.market.model.vo.Result;
import top.market.service.ICategoryService;

import java.util.List;

/**
 * <p>
 * 商品类别 前端控制器
 * </p>
 *
 * @author li yuhai
 * @since 2025-03-26
 */
@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    private ICategoryService categoryService;

    @GetMapping("/list")
    public Result getAllCategory() {
        List<Category> list = categoryService.list();
        return Result.ok("获取成功", list);
    }

    @PostMapping("/save")
    public Result save(@RequestBody Category category) {
        categoryService.save(category);
        return Result.ok("插入成功");
    }

    @PutMapping("/update")
    public Result updateCategory(@RequestBody Category category) {
        categoryService.updateById(category);
        return Result.ok("更新成功");
    }

    @DeleteMapping("/delete/{id}")
    public Result deleteCategory(@PathVariable Integer id) {
        categoryService.removeById(id);
        return Result.ok("删除成功");
    }

}
